package tagcloud.gui;

import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import javax.swing.BorderFactory;
import javax.swing.SwingConstants;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;

public class TagCloudPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	private JEditorPane textEditorPane = null;
	private JPanel topPanel = null;
	private JButton logoutButton = null;
	private JLabel accessCountLabel = null;
	private JPanel bottomPanel = null;
	private JButton uploadButton = null;
	private JButton nextButton = null;
	private ActionListener parentActionListener;
	
	/**
	 * This is the default constructor
	 */
	public TagCloudPanel(ActionListener parentActionListener) {
		super();
		this.parentActionListener = parentActionListener;
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
		gridBagConstraints8.gridx = 0;
		gridBagConstraints8.weightx = 1.0D;
		gridBagConstraints8.fill = GridBagConstraints.BOTH;
		gridBagConstraints8.gridy = 2;
		GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
		gridBagConstraints7.gridx = 0;
		gridBagConstraints7.fill = GridBagConstraints.BOTH;
		gridBagConstraints7.weightx = 0.0D;
		gridBagConstraints7.gridy = 0;
		GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
		gridBagConstraints2.fill = GridBagConstraints.BOTH;
		gridBagConstraints2.gridy = 1;
		gridBagConstraints2.weightx = 1.0;
		gridBagConstraints2.weighty = 1.0;
		gridBagConstraints2.gridwidth = 1;
		gridBagConstraints2.insets = new Insets(4, 0, 4, 0);
		gridBagConstraints2.gridx = 0;
		this.setSize(640, 480);
		this.setLayout(new GridBagLayout());
		this.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
		this.setName("TagCloud Panel");
		this.add(getBottomPanel(), gridBagConstraints8);
		this.add(getTextEditorPane(), gridBagConstraints2);
		this.add(getTopPanel(), gridBagConstraints7);
	}

	/**
	 * This method initializes textEditorPane	
	 * 	
	 * @return javax.swing.JEditorPane	
	 */
	private JEditorPane getTextEditorPane() {
		if (textEditorPane == null) {
			textEditorPane = new JEditorPane();
			textEditorPane.setText("[Document Text]");
			textEditorPane.setToolTipText("Enter the text you wish to have generated into a tag cloud.");
		}
		return textEditorPane;
	}

	/**
	 * This method initializes topPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getTopPanel() {
		if (topPanel == null) {
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.gridx = 0;
			gridBagConstraints1.ipady = 0;
			gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints1.weightx = 1.0D;
			gridBagConstraints1.insets = new Insets(0, 0, 0, 10);
			gridBagConstraints1.gridy = 0;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 1;
			gridBagConstraints.gridy = 0;
			accessCountLabel = new JLabel();
			accessCountLabel.setText("You can make # more Tag Clouds.");
			accessCountLabel.setHorizontalAlignment(SwingConstants.RIGHT);
			topPanel = new JPanel();
			topPanel.setLayout(new GridBagLayout());
			topPanel.add(getLogoutButton(), gridBagConstraints);
			topPanel.add(accessCountLabel, gridBagConstraints1);
		}
		return topPanel;
	}

	/**
	 * This method initializes logoutButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	protected JButton getLogoutButton() {
		if (logoutButton == null) {
			logoutButton = new JButton();
			logoutButton.setText("Logout");
			logoutButton.addActionListener(parentActionListener);
		}
		return logoutButton;
	}

	/**
	 * This method initializes bottomPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getBottomPanel() {
		if (bottomPanel == null) {
			bottomPanel = new JPanel();
			bottomPanel.setLayout(new BorderLayout());
			bottomPanel.add(getUploadButton(), BorderLayout.WEST);
			bottomPanel.add(getNextButton(), BorderLayout.EAST);
		}
		return bottomPanel;
	}

	/**
	 * This method initializes uploadButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	protected JButton getUploadButton() {
		if (uploadButton == null) {
			uploadButton = new JButton();
			uploadButton.setText("Upload Text");
			uploadButton.setToolTipText("Upload a text document to generate a cloud rather than using the text area.");
			uploadButton.addActionListener(parentActionListener);
		}
		return uploadButton;
	}

	/**
	 * This method initializes nextButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	protected JButton getNextButton() {
		if (nextButton == null) {
			nextButton = new JButton();
			nextButton.setText("Next >>");
			nextButton.addActionListener(parentActionListener);
		}
		return nextButton;
	}

}
